package com.app.freshmenapp.controller;

import com.app.freshmenapp.entity.Informs;
import com.app.freshmenapp.service.InformsService;
import com.app.freshmenapp.tools.FunctionExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Auther: Administrator
 * @Date: 2019.07.20 17:41
 * @Description:
 */

@RestController
@RequestMapping(value = "/annoucement")
public class InformsController {

    @Autowired
    private InformsService informsService;

    @Autowired
    private FunctionExample functionExample;

    @RequestMapping(value = "/list")
    public Map<String,Object> findAll(){
        List<Informs> list=informsService.findAllInforms();
        return functionExample.findAll(list);
    }

    @RequestMapping(value = "/findone/{id}")
    public Map<String,Object> findInforms(@PathVariable int id){
        Informs informs=informsService.findById(id);
        return functionExample.findOne(informs);
    }

    @RequestMapping(value = "/deleteone/{id}",method = RequestMethod.DELETE)
    public Map<String,Object> deleteInforms(@PathVariable int id){
        boolean judge=informsService.deleteInforms(id);
        return functionExample.otherOne(judge);
    }


    @RequestMapping(value = "/updateone",method = RequestMethod.PUT)
    public Map<String,Object> updateInforms(@RequestBody Informs informs){
        boolean judge=informsService.updateInforms(informs);
        return functionExample.otherOne(judge);
    }

    @RequestMapping(value = "/addone" ,method =RequestMethod.POST)
    public Map<String,Object> addInforms(@RequestBody Informs informs){
        boolean judge=informsService.addInforms(informs);
        return functionExample.otherOne(judge);
    }

}
